home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr44 / newmat08.zip / TMTI.CPP < prev    next >
C/C++ Source or Header  |  1995-01-17  |  6KB  |  192 lines

  1.  
  2. //#define WANT_STREAM
  3.  
  4. #include "include.h"
  5.  
  6. #include "newmatap.h"
  7. //#include "newmatio.h"
  8.  
  9. void Print(const Matrix& X);
  10. void Print(const UpperTriangularMatrix& X);
  11. void Print(const DiagonalMatrix& X);
  12. void Print(const SymmetricMatrix& X);
  13. void Print(const LowerTriangularMatrix& X);
  14.  
  15. void Clean(Matrix&, Real);
  16.  
  17. void WillNotConverge()
  18. {
  19.    Matrix A(10,10);
  20.    Throw(ConvergenceException(A));
  21. }
  22.  
  23. void ReDimensionMatrix(Matrix& A)
  24. // for seeing if we can redimension a vector as a matrix
  25. { A.ReDimension(4,5); }
  26.  
  27. void trymati()
  28. {
  29.    Tracer et("Eighteenth test of Matrix package");
  30.    Matrix RUStillThere(10,20); RUStillThere = 1553;
  31.    Exception::PrintTrace(TRUE);
  32.  
  33.    ProgramException::SetAction(0);           // turn off error messages
  34.    DataException::SetAction(0);
  35.    ConvergenceException::SetAction(0);
  36.    ColumnVector checks(16); checks = 1.0; checks(1) = 0.0;
  37.  
  38.    Try { WillNotConverge(); }
  39.    Catch(ConvergenceException) { checks(2) = 0; }
  40.    Catch(InternalException) { checks(1) = 1; }
  41.    Catch(ProgramException) { checks(1) = 1; }
  42.    Catch(DataException) { checks(1) = 1; }
  43.    Catch(SpaceException) { checks(1) = 1; }
  44.    CatchAndThrow;
  45.  
  46.    Try { Matrix M(10,10); SymmetricMatrix S = M; }
  47.    Catch(ConvergenceException) { checks(1) = 1; }
  48.    Catch(InternalException) { checks(1) = 1; }
  49.    Catch(ProgramException) { checks(3) = 0; }
  50.    Catch(DataException) { checks(1) = 1; }
  51.    Catch(SpaceException) { checks(1) = 1; }
  52.    CatchAndThrow;
  53.  
  54.    Try { Matrix M(10,10); M(10,11) = 2.0; }
  55.    Catch(ConvergenceException) { checks(1) = 1; }
  56.    Catch(InternalException) { checks(1) = 1; }
  57.    Catch(ProgramException) { checks(4) = 0; }
  58.    Catch(DataException) { checks(1) = 1; }
  59.    Catch(SpaceException) { checks(1) = 1; }
  60.    CatchAndThrow;
  61.  
  62.    Try { Matrix M(10,10); M = 0.0; M = M.i(); } 
  63.    Catch(ConvergenceException) { checks(1) = 1; }
  64.    Catch(InternalException) { checks(1) = 1; }
  65.    Catch(ProgramException) { checks(1) = 1; }
  66.    Catch(DataException) { checks(5) = 0; }
  67.    Catch(SpaceException) { checks(1) = 1; }
  68.    CatchAndThrow;
  69.  
  70.    Try { ColumnVector A(30), B(50);  A = 5; B = 3; FFT(A,B,A,B); } 
  71.    Catch(ConvergenceException) { checks(1) = 1; }
  72.    Catch(InternalException) { checks(1) = 1; }
  73.    Catch(ProgramException) { checks(6) = 0; }
  74.    Catch(DataException) { checks(1) = 1; }
  75.    Catch(SpaceException) { checks(1) = 1; }
  76.    CatchAndThrow;
  77.  
  78.    Try
  79.    {
  80.       ColumnVector A(30); A = 5; Matrix At = A.t();
  81.       DiagonalMatrix D;
  82.       SVD(At,D);
  83.    } 
  84.    Catch(ConvergenceException) { checks(1) = 1; }
  85.    Catch(InternalException) { checks(1) = 1; }
  86.    Catch(ProgramException) { checks(6) = 0; }
  87.    Catch(DataException) { checks(1) = 1; }
  88.    Catch(SpaceException) { checks(1) = 1; }
  89.    CatchAndThrow;
  90.  
  91.    Try { BandMatrix X(10,3,4); X(1,10) = 4.0; } 
  92.    Catch(ConvergenceException) { checks(1) = 1; }
  93.    Catch(InternalException) { checks(1) = 1; }
  94.    Catch(ProgramException) { checks(7) = 0; }
  95.    Catch(DataException) { checks(1) = 1; }
  96.    Catch(SpaceException) { checks(1) = 1; }
  97.    CatchAndThrow;
  98.  
  99.    Try
  100.    {
  101.       SymmetricMatrix S(10); S = 5;
  102.       LowerTriangularMatrix L = Cholesky(S);
  103.    } 
  104.    Catch(ConvergenceException) { checks(1) = 1; }
  105.    Catch(InternalException) { checks(1) = 1; }
  106.    Catch(ProgramException) { checks(1) = 1; }
  107.    Catch(DataException) { checks(8) = 0; }
  108.    Catch(SpaceException) { checks(1) = 1; }
  109.    CatchAndThrow;
  110.  
  111.    Try { BandMatrix M(10,3,5); M = 0.0; Matrix XM = M.i(); } 
  112.    Catch(ConvergenceException) { checks(1) = 1; }
  113.    Catch(InternalException) { checks(1) = 1; }
  114.    Catch(ProgramException) { checks(1) = 1; }
  115.    Catch(DataException) { checks(9) = 0; }
  116.    Catch(SpaceException) { checks(1) = 1; }
  117.    CatchAndThrow;
  118.  
  119.  
  120.    Try { ColumnVector X(10); ColumnVector Y; X = 5; X = X - Y; }
  121.    Catch(ConvergenceException) { checks(1) = 1; }
  122.    Catch(InternalException) { checks(1) = 1; }
  123.    Catch(ProgramException) { checks(10) = 0; }
  124.    Catch(DataException) { checks(1) = 1; }
  125.    Catch(SpaceException) { checks(1) = 1; }
  126.    CatchAndThrow;
  127.  
  128.    Try
  129.    {
  130.       UpperTriangularMatrix U(3); RowVector RV(3); RV = 10;
  131.       U.Row(2) = RV;
  132.    }
  133.    Catch(ConvergenceException) { checks(1) = 1; }
  134.    Catch(InternalException) { checks(1) = 1; }
  135.    Catch(ProgramException) { checks(11) = 0; }
  136.    Catch(DataException) { checks(1) = 1; }
  137.    Catch(SpaceException) { checks(1) = 1; }
  138.    CatchAndThrow;
  139.  
  140.    Try { DiagonalMatrix D(3); D << 12 << 13 << 14 << 15; }
  141.    Catch(ConvergenceException) { checks(1) = 1; }
  142.    Catch(InternalException) { checks(1) = 1; }
  143.    Catch(ProgramException) { checks(12) = 0; }
  144.    Catch(DataException) { checks(1) = 1; }
  145.    Catch(SpaceException) { checks(1) = 1; }
  146.    CatchAndThrow;
  147.  
  148.    Try { ColumnVector D(3); D << 12 << 13; D << 1 << 2 << 3; }
  149.    Catch(ConvergenceException) { checks(1) = 1; }
  150.    Catch(InternalException) { checks(1) = 1; }
  151.    Catch(ProgramException) { checks(13) = 0; }
  152.    Catch(DataException) { checks(1) = 1; }
  153.    Catch(SpaceException) { checks(1) = 1; }
  154.    CatchAndThrow;
  155.  
  156.  
  157.    Try {  { ColumnVector D(3); D << 12 << 13; }  }
  158.    Catch(ConvergenceException) { checks(1) = 1; }
  159.    Catch(InternalException) { checks(1) = 1; }
  160.    Catch(ProgramException) { checks(14) = 0; }
  161.    Catch(DataException) { checks(1) = 1; }
  162.    Catch(SpaceException) { checks(1) = 1; }
  163.    CatchAndThrow;
  164.  
  165.    Try { ColumnVector CV; ReDimensionMatrix(CV); }
  166.    Catch(ConvergenceException) { checks(1) = 1; }
  167.    Catch(InternalException) { checks(1) = 1; }
  168.    Catch(ProgramException) { checks(15) = 0; }
  169.    Catch(DataException) { checks(1) = 1; }
  170.    Catch(SpaceException) { checks(1) = 1; }
  171.    CatchAndThrow;
  172.  
  173.    Try { RowVector RV(20); ReDimensionMatrix(RV); }
  174.    Catch(ConvergenceException) { checks(1) = 1; }
  175.    Catch(InternalException) { checks(1) = 1; }
  176.    Catch(ProgramException) { checks(16) = 0; }
  177.    Catch(DataException) { checks(1) = 1; }
  178.    Catch(SpaceException) { checks(1) = 1; }
  179.    CatchAndThrow;
  180.  
  181.    ProgramException::SetAction(1);           // restore error messages
  182.    DataException::SetAction(1);
  183.    ConvergenceException::SetAction(1);
  184.  
  185.    Print(checks);
  186.    Matrix RUStillThere1(10,20); RUStillThere1 = 1553;
  187.    RUStillThere = RUStillThere - RUStillThere1;
  188.    Print(RUStillThere);
  189.  
  190.  
  191. }
  192.